<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" th:href="@{/admin/vendor/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/admin/vendor/font-awesome/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/admin/css/fontastic.css}">
    <link rel="stylesheet" th:href="@{/admin/css/style.default.css}" id="theme-stylesheet">
    <link rel="stylesheet" th:href="@{/admin/css/custom.css}">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
  </head>
  <body>
    <div class="page login-page">
      <div class="container d-flex align-items-center">
        <div class="form-holder has-shadow">
          <div class="row">
            <!-- Logo & Information Panel-->
            <div class="col-lg-6">
              <div class="info d-flex align-items-center">
                <div class="content">
                  <div class="logo">
                    <h1>Mandarin - Admin</h1>
                  </div>
                  <p>Mandarin administrators' management page</p>
                </div>
              </div>
            </div>
            <!-- Form Panel    -->
            <div class="col-lg-6 bg-white">
              <div class="form d-flex align-items-center">
                <div class="content">
                  <div method="post" class="form-validate">
                    <div class="form-group">
                      <input id="login-username" type="text" name="loginUsername" required data-msg="Please enter your username" class="input-material">
                      <label for="login-username" class="label-material">User Name / Phone Number</label>
                    </div>
                    <div class="form-group">
                      <input id="login-password" type="password" name="loginPassword" required data-msg="Please enter your password" class="input-material">
                      <label for="login-password" class="label-material">Password</label>
                    </div><button id="login" class="btn btn-primary">Login</button>
                    <!-- This should be submit button but I replaced it with <a> for demo purposes-->
                  </div><span class="forgot-pass" style="color: gray">Forgot Password?</span><br><small>Please contact the database administrator to reset your password</small>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="copyrights text-center">
      </div>
    </div>
    <!-- JavaScript files-->
    <script th:src="@{/admin/vendor/jquery/jquery.min.js}"></script>
    <script th:src="@{/admin/vendor/popper.js/umd/popper.min.js}"> </script>
    <script th:src="@{/admin/vendor/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/admin/vendor/jquery.cookie/jquery.cookie.js}"> </script>
    <script th:src="@{/admin/vendor/chart.js/Chart.min.js}"></script>
    <script th:src="@{/admin/vendor/jquery-validation/jquery.validate.min.js}"></script>
    <!-- Main File-->
    <script th:src="@{/admin/js/front.js}"></script>

    <script>
      $("#login").bind("click", function () {
        let formData = new FormData();
        formData.append("name", $("#login-username").val());
        formData.append("password", $("#login-password").val());

        $.ajax({
          url: "/api/user/token",
          type: "POST",
          dataType: "json",
          data: formData,
          processData: false,
          contentType: false,
          success: function (resp) {
            window.location.href="/admin/welcome";
          },
          error: function (resp) {
            alert(resp.message);
          }
        })
      })
    </script>
  </body>
</html>